﻿/// Jasig CAS server emulation with ASP.NET
/// by Uli Trampe
/// http://jasigemu.codeplex.com/
/// 
using System;
using System.Web.Security;
using Codeplex.JasigEmu;

namespace WebFormsCasClient
{
    public partial class Login : System.Web.UI.Page
    {
        private const string strCasServerUrl = "http://localhost:1547/Login.aspx/";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack) return;

            // handle everything that deals with CAS
            string strUserName, strErrorText;
            if (CasClient.HandlePageLoad(Login.strCasServerUrl, out strUserName, out strErrorText))
            {
                // no user name means that we are not authenticated yet
                if (strUserName != "") FormsAuthentication.RedirectFromLoginPage(strUserName, false);
            }
            else
            {
                // when the call failed then an error occured
                this.textFailed.Text = "The CAS server refused to validate your identity. Error text: " + strErrorText;
                this.textFailed.Visible = true;
            }
        }

    }
}
